package com.neulogistics.core.customercenter.api.application.converter;

import com.neulogistics.core.customercenter.api.application.command.CreateCustomerCommand;
import com.neulogistics.core.customercenter.api.application.command.UpdateCustomerCommand;
import com.neulogistics.core.customercenter.domain.model.aggregate.Customer;
import com.neulogistics.core.customercenter.domain.model.valueobject.Address;

public class CustomerEntityCommandConverter {
    public static Customer commandToEntity(CreateCustomerCommand command){
        if(command == null)
            return null;

        String customerName = command.getCustomerName();
        String flatsName = command.getFlatsName();
        String customerIdentity = command.getCustomerIdentity();
        String customerPhone = command.getCustomerPhone();
        Address receiverAddress = command.getReceiverAddress();
        String customerEmail = command.getCustomerEmail();
        String customerLandline = command.getCustomerLandline();

        Customer customer = new Customer(customerName, flatsName, customerIdentity,
                customerPhone, receiverAddress, customerEmail, customerLandline);

        return customer;
    }

    public static Customer commandToEntity(UpdateCustomerCommand command){
        if(command == null)
            return null;

        Customer customer = new Customer();
        customer.setCustomerName(command.getCustomerName());
        customer.setFlatsName(command.getFlatsName());
        customer.setCustomerPhone(command.getCustomerPhone());
        customer.setReceiverAddress(command.getReceiverAddress());
        customer.setCustomerEmail(command.getCustomerEmail());
        customer.setCustomerLandline(command.getCustomerLandline());
        customer.setCustomerId(command.getCustomerId());

        return customer;
    }
}
